package com.xh.one2one.base.service.impl;

import com.xh.one2one.base.bean.request.SpeechcraftRequest;
import com.xh.one2one.base.model.Speechcraft;
import com.xh.one2one.base.dao.SpeechcraftMapper;
import com.xh.one2one.base.service.ISpeechcraftService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;
import java.util.List;
/**
 * <p>
 * 一对一话术 服务实现类
 * </p>
 *
 * @author TW
 * @since 2021-05-08
 */
@Service
public class SpeechcraftServiceImpl extends BaseServiceImpl<SpeechcraftMapper, Speechcraft> implements ISpeechcraftService {
    @Override
    public XhPage  querySpeechcraftPage(XhPage page, SpeechcraftRequest bean) {
        QueryWrapper qw=new QueryWrapper<Speechcraft>();
        //拼装条件
        qw=prepareParams(bean, qw);
        if(StringUtils.isNotEmpty(bean.getText())){
            qw.like("text",bean.getText());
        }
        if(bean.getGrade()!=null){
            qw.eq("grade",bean.getGrade());
        }
        if(bean.getLevelIds()!=null && bean.getLevelIds().size()>0){
            qw.in("level_id",bean.getLevelIds());
        }

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List querySpeechcraft(SpeechcraftRequest bean) {
        QueryWrapper qw=new QueryWrapper<Speechcraft>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(SpeechcraftRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
